import request from '@/utils/request'
import { SkuResponseData, SkuInfoResponseData } from './type'

enum SKU_API_URL {
  /**
   * 获取SKU信息的地址
   */
  GET_SKU_URL = '/admin/product/list',

  /**
   * 上架SKU的地址
   */
  SALE_SKU_URL = '/admin/product/onSale',

  /**
   * 下架SKU的地址
   */
  CANCEL_SALESKU_URL = '/admin/product/cancelSale',

  /**
   * 获取SKU商品信息
   */
  GET_SKU_INFO_URL = '/admin/product/getSkuInfo',

  /**
   * 删除SKU商品信息
   */
  DELETE_SKU_URL = '/admin/product/deleteSku',
}

/**
 * 获取SKU信息的接口方法
 * @param pageNo
 * @param limit
 * @returns Promise<SkuResponseData>
 */
export const reqGetSku = (pageNo: number, limit: number): Promise<SkuResponseData> =>
  request.get<any, SkuResponseData>(SKU_API_URL.GET_SKU_URL + `/${pageNo}/${limit}`)

/**
 * 上架SKU的接口方法
 * @param skuId
 * @returns Promise<any>
 */
export const reqSaleSku = (skuId: number): Promise<any> =>
  request.get<any, any>(SKU_API_URL.SALE_SKU_URL + `/${skuId}`)

/**
 * 下架SKU的接口方法
 * @param skuId
 * @returns Promise<any>
 */
export const reqCancelSaleSku = (skuId: number): Promise<any> =>
  request.get<any, any>(SKU_API_URL.CANCEL_SALESKU_URL + `/${skuId}`)

/**
 * 获取SKU商品信息
 * @param skuId
 * @returns Promise<SkuInfoResponseData>
 */
export const reqSkuInfo = (skuId: number): Promise<SkuInfoResponseData> =>
  request.get<any, SkuInfoResponseData>(SKU_API_URL.GET_SKU_INFO_URL + `/${skuId}`)

/**
 * 删除SKU商品信息
 * @param skuId
 * @returns Promise<any>
 */
export const reqDeleteSku = (skuId: number): Promise<any> =>
  request.delete<any, any>(SKU_API_URL.DELETE_SKU_URL + `/${skuId}`)
